package com.doyle.musicplus.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.History;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.event.logical.shared.*;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class Doyle_music_plus implements EntryPoint, ValueChangeHandler<String> {
	/**
	 * The message displayed to the user when the server cannot be reached or
	 * returns an error.
	 */
	private static final String SERVER_ERROR = "An error occurred while "
			+ "attempting to contact the server. Please check your network "
			+ "connection and try again.";

	String startingToken = "";
	/**
	 * This is the entry point method.
	 */
	public void onModuleLoad() {
		
		History.addValueChangeHandler(this);
		History.newItem(LoginPresenter.PLACE, true);
	}

	@Override
	public void onValueChange(ValueChangeEvent<String> event) {
		
		executeInPanel(RootPanel.get(), event.getValue());
		
	}
	
	private void executeInPanel(RootPanel myPanel, String token) {
		
		if (myPanel==null) {
			myPanel = RootPanel.get();
		}
		myPanel.clear();
		
		if (token.isEmpty()) {
			
		} else if (token.equals(LoginPresenter.PLACE)) {
			
		}
		
	}

	void showLogin() {
		
	}
	
	void showMainMenu() {
		
		if(!startingToken.isEmpty()) {
			History.newItem(startingToken, true);
			startingToken = "";
		}
	}
	
}
